package com.mytrip.webapp.action;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.mytrip.base.action.StrutsActionAdapter;
import com.mytrip.model.Userinfo;
import com.mytrip.service.UserManager;
import com.mytrip.webapp.filter.CtxSessionBag;

public class MyDetailAction extends StrutsActionAdapter {
	/**
	 * 
	 */
	private static final long serialVersionUID = 493024061360867403L;
	private Userinfo user = new Userinfo();
	private UserManager userManager;
	
	public String myDetail() throws Exception {
		return SUCCESS;
	}
	
	public String goChangepw() throws Exception {

		return "goChangepw";
	}
	
	public String goFfriend() throws Exception {

		return "goFfriend";
	}
	
	public String changepwd() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer userid = Integer.valueOf(request.getParameter("userid"));

		return "changepwd";
	}
	
	public String address() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer userid = Integer.valueOf(request.getParameter("userid"));

		return "address";
	}
	
	public String goAddress() throws Exception {

		return "goAddress";
	}
	
	public String updateUser() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer userid = Integer.valueOf(request.getParameter("userid"));
		String email = request.getParameter("email");
		String password = request.getParameter("pwd");
		String realName = request.getParameter("realName");
		String gender = request.getParameter("gender");
		String photo = request.getParameter("photo");
		String mobile = request.getParameter("mobile");
		String address = request.getParameter("address");
		//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		user.setId(userid);
		user.setEmail(email);
		user.setPwd(password);
		user.setRealName(realName);
//		user.setAddress(address);
		user.setGender(gender);
		user.setPhoto(photo);
		user.setMobile(mobile);

		int i = userManager.updateUserinfo(user);
		CtxSessionBag.getSessionBag().setUserinfo(user);

		return "updateuser";
	}

	public String findFriend() throws Exception {

		return "findFriend";
	}
	
	public Userinfo getUser() {
		return user;
	}

	public void setUser(Userinfo user) {
		this.user = user;
	}

	public UserManager getUserManager() {
		return userManager;
	}

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	
	
}
